<template>
  <!-- 布局容器 -->
  <el-container class="container">
    <!-- 左侧栏 -->
    <el-aside width="200px">
      <div class="logo"></div>
      <!-- 导航菜单 -->
      <!-- default-active="1" 通过el-menu-item的index的值来激活菜单项 -->
      <el-menu
        background-color="#234"
        text-color="#fff"
        :default-active="$route.path"
        style="border-right:none"
        router
      >
        <el-menu-item index="/">
          <i class="el-icon-s-home"></i>
          <span slot="title">数据概览</span>
        </el-menu-item>
        <el-menu-item index="/article">
          <i class="el-icon-document"></i>
          <span slot="title">内容管理</span>
        </el-menu-item>
        <el-menu-item index="/publish">
          <i class="el-icon-s-promotion"></i>
          <span slot="title">发布文章</span>
        </el-menu-item>
      </el-menu>
    </el-aside>
    <!-- 右侧内容 -->
    <el-container>
      <!-- 头部 -->
      <el-header>
        <span style="margin-right:10px">{{user.name||user.mobile}}</span>
        <el-link @click="logout()" :underline="false" icon="el-icon-unlock">退出</el-link>
      </el-header>
      <!-- 内容 -->
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>
<script>
import auth from '@/utils/auth'
export default {
  name: 'Layout',
  data () {
    return {
      // 用户信息对象
      user: {}
    }
  },
  async created () {
    // 获取数据，设置数据
    const res = await this.$http.get('/v1_0/user/profile')
    this.user = res.data.data
  },
  methods: {
    logout () {
      // 1. 删除token
      // 2. 跳转登录
      auth.delToken()
      this.$router.push('/login')
    }
  }
}
</script>
<style scoped lang="less">
.container {
  position: absolute;
  width: 100%;
  height: 100%;
  .el-aside {
    background: #234;
    .logo {
      background: url(../assets/logo.png) no-repeat center / 140px auto;
      width: 100%;
      height: 60px;
    }
  }
  .el-header {
    border-bottom: 1px solid #ddd;
    line-height: 60px;
    display: flex;
    justify-content: flex-end;
  }
}
</style>
